package com.sg.service.biz.calc.nb;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.sg.dto.biz.calc.req.*;
import com.sg.dto.biz.calc.res.*;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author ： 手工接入方法
 * @version 1.0
 * @since 2022/5/28 15:32
 */
@Service
public class NbCalculationRules {
    /**
     * code:complexCalcOfTwoNum
     * name:M-计算两个数复合计算（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:08:57 PM
     **/
    @Trace(operationName = "M-计算两个数复合计算（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateComplexCalcOfTwoNumServiceRespDto calculateComplexCalcOfTwoNumService(CalculateComplexCalcOfTwoNumServiceReqDto reqDto) {
        CalculateComplexCalcOfTwoNumServiceRespDto retData = new CalculateComplexCalcOfTwoNumServiceRespDto();
        int mode = BigDecimal.ROUND_HALF_UP;
        if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
            mode = BigDecimal.ROUND_DOWN;
        }
        BigDecimal calcPara1 = new BigDecimal(reqDto.getCalcPara1().toString());
        BigDecimal calcPara2 = new BigDecimal(reqDto.getCalcPara2().toString());
        BigDecimal calcPara3 = new BigDecimal(reqDto.getCalcPara3().toString());
        BigDecimal calcPara4 = new BigDecimal(reqDto.getCalcPara4().toString());
        BigDecimal subjectScorePoint = new BigDecimal(reqDto.getSubjectiveScorePoint().intValue());

        BigDecimal calcResult = calcPara1.multiply(calcPara2).add(calcPara3.multiply(calcPara4));
        calcResult = calcResult.setScale(subjectScorePoint.scale(), mode);

        retData.setCalcResult(calcResult.doubleValue());
        return retData;

    }

    /**
     * code:partAveOfMultipleNum
     * name:M4-计算数据集去除最大最小求平均（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:06 PM
     **/
    @Trace(operationName = "M4-计算数据集去除最大最小求平均（特殊方法）")
    @Tags({@Tag(key = "参数", value = " arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculatePartAveOfMultipleNumRespDto calculatePartAveOfMultipleNum(CalculatePartAveOfMultipleNumReqDto reqDto) {
        CalculatePartAveOfMultipleNumRespDto retData = new CalculatePartAveOfMultipleNumRespDto();
        List<PartAveOfMultipleNumDto> list = reqDto.getPartAveOfMultipleNumList();
        BigDecimal calcResult = BigDecimal.ZERO;
        int size = list.size();
        if (size == 0) {
            return retData;
        }

        int mode = BigDecimal.ROUND_HALF_UP;
        if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
            mode = BigDecimal.ROUND_DOWN;
        }

        if (size == 1) {
            calcResult = new BigDecimal(list.get(0).getDataResult().toString());
            calcResult = calcResult.setScale(reqDto.getDecimalPointRules().intValue(), mode);
            retData.setCalcResult(calcResult.doubleValue());
            return retData;
        }

        if (size == 2) {
            BigDecimal result = list.stream().map(data -> {
                BigDecimal elm = new BigDecimal(data.getDataResult().toString());
                return elm;
            }).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(2), reqDto.getDecimalPointRules().intValue(), mode);

            retData.setCalcResult(result.doubleValue());

            return retData;
        }

        if (size > 2) {
            list.sort((u1, u2) -> u1.getCalcPara1().compareTo(u2.getCalcPara1()));
        }

        BigDecimal result = list.stream().skip(1).limit(list.size() - 2).map(data -> {
            BigDecimal elm = new BigDecimal(data.getCalcPara1().toString());
            return elm;
        }).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(list.size() - 2), reqDto.getDecimalPointRules().intValue(), mode);

        retData.setCalcResult(result.doubleValue());

        return retData;
    }

    /**
     * code:averageOfMultipleNum
     * name:M4-计算数据集求平均值（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:07 PM
     **/
    @Trace(operationName = "M4-计算数据集求平均值（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateAverageOfMultipleNumRespDto calculateAverageOfMultipleNum(CalculateAverageOfMultipleNumReqDto reqDto) {
        CalculateAverageOfMultipleNumRespDto retData = new CalculateAverageOfMultipleNumRespDto();

        int mode = BigDecimal.ROUND_HALF_UP;
        if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
            mode = BigDecimal.ROUND_DOWN;
        }

        int size = reqDto.getAverageOfMultipleNumList().size();

        BigDecimal result = reqDto.getAverageOfMultipleNumList().stream().map(data -> {
            BigDecimal elm = new BigDecimal(data.getCalcPara1().toString());
            return elm;
        }).reduce(BigDecimal.ZERO, BigDecimal::add).divide(BigDecimal.valueOf(size), reqDto.getDecimalPointRules().intValue(), mode);

        retData.setCalcResult(result.doubleValue());
        return retData;
    }

    /**
     * code:minimumOfMultipleNum
     * name:M4-计算数据集求最小值（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:08 PM
     **/
    @Trace(operationName = "M4-计算数据集求最小值（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateMinimumOfMultipleNumRespDto calculateMinimumOfMultipleNum(CalculateMinimumOfMultipleNumReqDto reqDto) {
        CalculateMinimumOfMultipleNumRespDto retData = new CalculateMinimumOfMultipleNumRespDto();
        MinimumOfMultipleNumDto min = null;
        if (reqDto.getMinimumOfMultipleNumList().size() == 0) {
            return retData;
        }
        for (MinimumOfMultipleNumDto one : reqDto.getMinimumOfMultipleNumList()) {
            if (min == null) {
                min = one;
            }

            if (min.getDataResult() > one.getDataResult()) {
                min = one;
            }
        }

        retData.setCalcResult(min.getDataResult());
        return retData;
    }

    /**
     * code:maxOfMultipleNum
     * name:M4-计算数据集求最大值（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:10 PM
     **/
    @Trace(operationName = "M4-计算数据集求最大值（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateMaxOfMultipleNumRespDto calculateMaxOfMultipleNum(CalculateMaxOfMultipleNumReqDto reqDto) {
        CalculateMaxOfMultipleNumRespDto retData = new CalculateMaxOfMultipleNumRespDto();
        MaxOfMultipleNumDto max = null;
        if (reqDto.getMaxOfMultipleNumList().size() == 0) {
            return retData;
        }
        for (MaxOfMultipleNumDto one : reqDto.getMaxOfMultipleNumList()) {
            if (max == null) {
                max = one;
            }

            if (max.getDataResult() > one.getDataResult()) {
                max = one;
            }
        }

        retData.setCalcResult(max.getDataResult());
        return retData;
    }

    /**
     * code:newestOfMultipleNum
     * name:M4-计算数据集取最新（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:11 PM
     **/
    @Trace(operationName = "M4-计算数据集取最新（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateNewestOfMultipleNumRespDto calculateNewestOfMultipleNum(CalculateNewestOfMultipleNumReqDto reqDto) {
        CalculateNewestOfMultipleNumRespDto retData = new CalculateNewestOfMultipleNumRespDto();
        int mode = -1;
        if (reqDto.getDecimalDigitsLastRules() != null) {
            mode = BigDecimal.ROUND_HALF_UP;
            if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
                mode = BigDecimal.ROUND_DOWN;
            }
        }
        NewestOfMultipleNumDto target = null;
        if (reqDto.getNewestOfMultipleNumList().size() == 0) {
            return retData;
        }
        for (NewestOfMultipleNumDto one : reqDto.getNewestOfMultipleNumList()) {
            if (target == null) {
                target = one;
            }
            if (one.getComTimeField().getTime() > target.getComTimeField().getTime()) {
                target = one;
            }
        }
        BigDecimal calcResult = new BigDecimal(target.getCalcPara1().toString());
        if (mode != -1) {
            calcResult = calcResult.setScale(reqDto.getDecimalPointRules().intValue(), mode);
        }
        retData.setCalcResult(calcResult.doubleValue());
        retData.setCommPrimaryKey(target.getCommPrimaryKey());
        return retData;
    }

    /**
     * code:calculateActualValue
     * name:M-计算角色主观得分
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:14 PM
     **/
    @Trace(operationName = "M-计算角色主观得分")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateRoleSubjectiveScoreRespDto calculateRoleSubjectiveScore(CalculateRoleSubjectiveScoreReqDto reqDto) {
        CalculateRoleSubjectiveScoreRespDto retData = new CalculateRoleSubjectiveScoreRespDto();

        int mode = BigDecimal.ROUND_HALF_UP;
        if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
            mode = BigDecimal.ROUND_DOWN;
        }

        BigDecimal calcPara1 = new BigDecimal(reqDto.getCalcPara1().toString());
        BigDecimal calcPara2 = new BigDecimal(reqDto.getCalcPara2().toString());
        BigDecimal calcPara3 = new BigDecimal(reqDto.getCalcPara3().toString());
        BigDecimal calcPara4 = new BigDecimal(reqDto.getCalcPara4().toString());
        BigDecimal subjectiveScorePoint = new BigDecimal(reqDto.getSubjectiveScorePoint().intValue());
        BigDecimal subjectiveTotalValue = new BigDecimal(reqDto.getSubjectiveRatingTotalValue());

        // 参数1、参数2、参数3相乘
        BigDecimal numerator = calcPara1.multiply(calcPara2).multiply(calcPara3);

// totalValue和参数4相乘
        BigDecimal denominator = subjectiveTotalValue.multiply(calcPara4);

// 两者相除，注意要处理除数为0的情况
        BigDecimal result;
        if (denominator.compareTo(BigDecimal.ZERO) != 0) { // 确保分母不为0
            result = numerator.divide(denominator, subjectiveScorePoint.scale(), mode);
        } else {
            // 分母为0的情况处理，比如可以抛出异常或者设置特定的返回值
            throw new ArithmeticException("Division by zero is not allowed.");
        }

        retData.setCalcResult(result.doubleValue());
        return retData;
    }

    /**
     * code:complexCalcOfMultipleNum
     * name:M4-数据集复合计算（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:15 PM
     **/
    @Trace(operationName = "M4-数据集复合计算（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public AddComplexCalcOfMultipleNumRespDto addComplexCalcOfMultipleNum(AddComplexCalcOfMultipleNumReqDto reqDto) {
        AddComplexCalcOfMultipleNumRespDto retData = new AddComplexCalcOfMultipleNumRespDto();
        int mode = -1;
        if (reqDto.getDecimalDigitsLastRules() != null) {
            mode = BigDecimal.ROUND_HALF_UP;
            if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
                mode = BigDecimal.ROUND_DOWN;
            }
        }
        BigDecimal calcResult = new BigDecimal("0");
        for (ComplexCalcOfMultipleNumDto one : reqDto.getComplexCalcOfMultipleNumList()) {
            System.out.println("mode 0:" + mode);
            BigDecimal multiplier = new BigDecimal(one.getCalcPara1().toString()).multiply(new BigDecimal(one.getCalcPara2().toString()));
            calcResult = calcResult.add(multiplier);  // 无需在此处指定 scale 或 mode
            System.out.println("calcResult1:" + calcResult);
        }
        if (mode != -1) {
            calcResult = calcResult.setScale(reqDto.getDecimalPointRules().intValue(), mode);
            System.out.println("calcResultb 2:" + calcResult);
        }
        retData.setCalcResult(calcResult.doubleValue());
        System.out.println("calcResult 3" + retData.getCalcResult());
        return retData;
    }

    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }

    /**
     * code:sumOfMultipleNum
     * name:M4-计算数据集求和（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:17 PM
     **/
    @Trace(operationName = "M4-计算数据集求和（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public AddSumOfMultipleNumRespDto addSumOfMultipleNum(AddSumOfMultipleNumReqDto reqDto) {
        AddSumOfMultipleNumRespDto retData = new AddSumOfMultipleNumRespDto();
        int mode = -1;
        if (reqDto.getDecimalDigitsLastRules() != null) {
            mode = BigDecimal.ROUND_HALF_UP;
            if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
                mode = BigDecimal.ROUND_DOWN;
            }
        }

        BigDecimal calcResult = new BigDecimal("0");
        for (SumOfMultipleNumDto one : reqDto.getSumOfMultipleNumList()) {
            calcResult = calcResult.add(new BigDecimal(one.getCalcPara1().toString()));
        }
        if (mode != -1) {
            calcResult = calcResult.setScale(reqDto.getDecimalPointRules().intValue(), mode);
        }
        retData.setCalcResult(calcResult.doubleValue());
        return retData;
    }

    /**
     * code:ratioOfTwoNum
     * name:M-计算两个数值比（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:18 PM
     **/
    @Trace(operationName = "M-计算两个数值比（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateRatioOfTwoNumRespDto calculateRatioOfTwoNum(CalculateRatioOfTwoNumReqDto reqDto) {
        CalculateRatioOfTwoNumRespDto retData = new CalculateRatioOfTwoNumRespDto();

        int mode = BigDecimal.ROUND_HALF_UP;
        if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
            mode = BigDecimal.ROUND_DOWN;
        }

        if (reqDto.getCalcPara1() == null || reqDto.getCalcPara2() == null) {
            return retData;
        }


        BigDecimal calcPara1 = new BigDecimal(reqDto.getCalcPara1().toString());
        BigDecimal calcPara2 = new BigDecimal(reqDto.getCalcPara2().toString());
        BigDecimal calcPara3 = new BigDecimal(reqDto.getCalcPara3().toString());

        BigDecimal result = calcPara1.multiply(calcPara3).divide(calcPara2, reqDto.getDecimalPointRules().intValue(), mode);
        retData.setCalcResult(result.doubleValue());
        return retData;
    }

    /**
     * code:ratioBetweenTwoNum
     * name:M-计算两个数差额比（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:19 PM
     **/
    @Trace(operationName = "M-计算两个数差额比（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateRatioBetweenTwoNumRespDto calculateRatioBetweenTwoNum(CalculateRatioBetweenTwoNumReqDto reqDto) {
        CalculateRatioBetweenTwoNumRespDto retData = new CalculateRatioBetweenTwoNumRespDto();
        int mode = BigDecimal.ROUND_HALF_UP;
        if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
            mode = BigDecimal.ROUND_DOWN;
        }
        BigDecimal calcPara1 = new BigDecimal(reqDto.getCalcPara1().toString());
        BigDecimal calcPara2 = new BigDecimal(reqDto.getCalcPara2().toString());

        BigDecimal result = calcPara1.subtract(calcPara2).divide(calcPara2, reqDto.getDecimalPointRules().intValue(), mode);
        retData.setCalcResult(result.doubleValue());
        return retData;
    }

    /**
     * code:additionOfTwoNum
     * name:M-计算两个数相加（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:21 PM
     **/
    @Trace(operationName = "M-计算两个数相加（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateAdditionOfTwoNumRespDto calculateAdditionOfTwoNum(CalculateAdditionOfTwoNumReqDto reqDto) {
        CalculateAdditionOfTwoNumRespDto retData = new CalculateAdditionOfTwoNumRespDto();
        int mode = -1;
        if (reqDto.getDecimalDigitsLastRules() != null) {
            mode = BigDecimal.ROUND_HALF_UP;
            if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
                mode = BigDecimal.ROUND_DOWN;
            }
        }

        if (reqDto.getCalcPara1() != null && reqDto.getCalcPara2() != null) {
            BigDecimal calcPara1 = new BigDecimal(reqDto.getCalcPara1().toString());
            BigDecimal calcPara2 = new BigDecimal(reqDto.getCalcPara2().toString());

            // Perform addition with proper BigDecimal arithmetic
            BigDecimal result = calcPara1.add(calcPara2);
            if (mode != -1) {
                result = result.setScale(reqDto.getDecimalPointRules().intValue(), mode);
            }
            retData.setCalcResult(result.doubleValue());
        }

        if (reqDto.getCalcPara1() != null && reqDto.getCalcPara2() == null) {
            retData.setCalcResult(reqDto.getCalcPara1());
        }

        if (reqDto.getCalcPara2() != null && reqDto.getCalcPara1() == null) {
            retData.setCalcResult(reqDto.getCalcPara2());
        }
        return retData;
    }

    /**
     * code:subtractionOfTwoNum
     * name:M-计算两个数相减（特殊方法）
     * desc:undefined
     * gen by moon at 8/28/2022, 4:09:22 PM
     **/
    @Trace(operationName = "M-计算两个数相减（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateSubtractionOfTwoNumRespDto calculateSubtractionOfTwoNum(CalculateSubtractionOfTwoNumReqDto reqDto) {
        CalculateSubtractionOfTwoNumRespDto retData = new CalculateSubtractionOfTwoNumRespDto();
        int mode = -1;
        if (reqDto.getDecimalDigitsLastRules() != null) {
            mode = BigDecimal.ROUND_HALF_UP;
            if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
                mode = BigDecimal.ROUND_DOWN;
            }
        }
        if (reqDto.getCalcPara1() != null && reqDto.getCalcPara2() != null) {
            BigDecimal calcPara1 = new BigDecimal(reqDto.getCalcPara1().toString());
            BigDecimal calcPara2 = new BigDecimal(reqDto.getCalcPara2().toString());
            BigDecimal result = calcPara1.subtract(calcPara2);
            if (mode != -1) {
                result = result.setScale(reqDto.getDecimalPointRules().intValue(), mode);
            }
            retData.setCalcResult(result.doubleValue());
        }
        return retData;
    }

    /**
     * code:divisionOfTwoNum
     * name:M4-计算两个数值相除（特殊方法）
     * desc:undefined
     * gen by moon at 10/14/2022, 11:53:49 PM
     **/
    @Trace(operationName = "M4-计算两个数值相除（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateDivisionOfTwoNumRespDto calculateDivisionOfTwoNum(CalculateDivisionOfTwoNumReqDto reqDto) {
        CalculateDivisionOfTwoNumRespDto retData = new CalculateDivisionOfTwoNumRespDto();
        int mode = -1;
        if (reqDto.getDecimalDigitsLastRules() != null) {
            mode = BigDecimal.ROUND_HALF_UP;
            if (reqDto.getDecimalDigitsLastRules().equals("MALING")) {
                mode = BigDecimal.ROUND_DOWN;
            }
        }
        if (reqDto.getCalcPara1() != null && reqDto.getCalcPara2() != null) {
            BigDecimal one = new BigDecimal(reqDto.getCalcPara1().toString());
            BigDecimal two = new BigDecimal(reqDto.getCalcPara2().toString());
            BigDecimal result = one.divide(two, reqDto.getDecimalPointRules().intValue(), mode);
            retData.setCalcResult(result.doubleValue());
        }
        return retData;
    }

    public static void main1(String[] args) {
        NbCalculationRules o = new NbCalculationRules();

        CalculateDivisionOfTwoNumReqDto req = new CalculateDivisionOfTwoNumReqDto();
        req.setCalcPara1(10.1d);
        req.setCalcPara2(1d);
        req.setDecimalPointRules(10l);
        req.setDecimalDigitsLastRules("MALING");
        CalculateDivisionOfTwoNumRespDto ret = o.calculateDivisionOfTwoNum(req);
        System.out.println(ret);
    }

    /**
     * code:receptionService
     * name:约定出参字段：计算结果
     * desc:undefined
     * gen by moon at 2/26/2023, 1:42:22 PM
     **/
    @Trace(operationName = "约定出参字段：计算结果")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public ImplementReceiveFieldRespDto implementReceiveField(ImplementReceiveFieldReqDto reqDto) {
        return BeanUtil.toBean(reqDto, ImplementReceiveFieldRespDto.class);
    }

    /**
     * code:oldestOfMultipleNum
     * name:M4-计算数据集取最早（特殊方法）
     * desc:undefined
     * gen by moon at 6/23/2023, 11:44:39 PM
     **/
    @Trace(operationName = "M4-计算数据集取最早（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public CalculateOldestOfMultipleNumRespDto calculateOldestOfMultipleNum(CalculateOldestOfMultipleNumReqDto reqDto) {
        CalculateOldestOfMultipleNumRespDto retData = new CalculateOldestOfMultipleNumRespDto();

        if (CollectionUtil.isNotEmpty(reqDto.getOldestOfMultipleNumList())) {
            OldestOfMultipleNumDto target = reqDto.getOldestOfMultipleNumList().get(0);
            for (OldestOfMultipleNumDto one : reqDto.getOldestOfMultipleNumList()) {
                if (one.getComTimeField().compareTo(target.getComTimeField()) < 0) {
                    target = one;
                }
            }
            retData.setCommPrimaryKey(target.getCommPrimaryKey());
        }
        return retData;
    }
    //手工接入方法
}
